home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir30 / eerems11.zip / EER_DLG.C < prev    next >
C/C++ Source or Header  |  1994-10-23  |  7KB  |  231 lines

  1. /* ***************************************************************
  2.  
  3. An AutoCAD ADS program to remove "extra entities"
  4.  
  5. This module contains the functions to run the dialog box version
  6.  
  7. Jon Fleming    CIS 70334,2443    July 19, 1994
  8.  
  9. Public Domain; Please give me credit if you use this or any
  10. significant portion of it
  11.  
  12. Revision history:
  13.  
  14. July 19, 1994  Version 1.0: Initial release
  15.  
  16. October 23, 1994 Version 1.1: Modified EER_CORE.C to handle negative line
  17.     endpoints properly, and to avoid checking for entities to remove when
  18.     no entities were selected in the "candidates for removal" selection set.
  19.     Modified EER_CORE.C and EEREM.H to include version number report when
  20.     DoEntityRemoval starts.
  21.  
  22. *********************************************************** */
  23.  
  24. #include <string.h>
  25. #include  "adslib.h"
  26. #include "adsdlg.h"
  27. #include "eerem.h"
  28.  
  29. /* Function prototypes */
  30.  
  31. int ddeerem ();
  32. void CALLB OKCallBack(ads_callback_packet *);
  33. void CALLB SelectCallBack(ads_callback_packet *);
  34.  
  35. /* Coordinates for the dialog box position on the screen */
  36.  
  37. static int DialogX = -1, DialogY = -1;
  38.  
  39. /* Indicators for whether to consider layer, linetype, and/or color */
  40.  
  41. extern int CheckLayer, CheckLType, CheckColor;
  42.  
  43. /* Tolerance within which numbers are considered equal (at least, that's
  44.    approximately what this is; see below for more detail)  */
  45.  
  46. extern ads_real Tolerance;
  47.  
  48. /* Character versions of the above, for the dialog box */
  49.  
  50. char ToleranceStr[13], CheckLayerStr[2], CheckLTypeStr[2], CheckColorStr[2];
  51.  
  52.  
  53.  
  54. /* Function for doing extra entity removal from the command line through
  55.    a dialog box.
  56.  
  57.    Return value:
  58.  
  59.    T / RSRLST if the DCL file and dialog box definiton were found
  60.  
  61.    NIL / RSERR otherwise
  62. */
  63.  
  64. int ddeerem () {
  65.  
  66.    ads_name SelSet;
  67.  
  68.    ads_hdlg DialogHandle;
  69.  
  70.    int DialogStatus = 10, DCL_ID, stat = RSRSLT;
  71.    
  72.    short EntitiesNotSelected = 1;
  73.  
  74.    int LastTolChar;
  75.  
  76.    char ZeroChar[] = "0";
  77.  
  78.    /* Set up the default values of the tiles */
  79.  
  80.    ads_rtos(Tolerance, 2, 12, ToleranceStr);
  81.    /* Strip trailing zeros */
  82.    LastTolChar = strlen(ToleranceStr) - 1;
  83.    while (ToleranceStr[LastTolChar] == ZeroChar[0]) {
  84.       ToleranceStr[LastTolChar] = 0;
  85.       LastTolChar = --LastTolChar;
  86.    }
  87.  
  88.  
  89.    if (CheckLayer) {
  90.       strcpy(CheckLayerStr, "1");
  91.    }
  92.    else {
  93.       strcpy(CheckLayerStr, "0");
  94.    }
  95.    if (CheckLType) {
  96.       strcpy(CheckLTypeStr, "1");
  97.    }
  98.    else {
  99.       strcpy(CheckLTypeStr, "0");
  100.    }
  101.    if (CheckColor) {
  102.       strcpy(CheckColorStr, "1");
  103.    }
  104.    else {
  105.       strcpy(CheckColorStr, "0");
  106.    }
  107.  
  108.    /* Open the dialog box.  The loop allows us to pop back up after picking
  109.       entities for checking */
  110.  
  111.    if (ads_load_dialog("EEREM.DCL", &DCL_ID) == RTNORM) {
  112.       while (DialogStatus > 1) {
  113.          if (ads_new_positioned_dialog("eerem", DCL_ID, NULLCB, DialogX, DialogY, &DialogHandle) == RTNORM) {
  114.             
  115.             /* Disable the OK button until entities are selected.
  116.                EntitiesNotSelected should be a SHORT with a value of
  117.                0 to indicate entities have been selected, 1 to indicate
  118.                entities have not yet been selected, and NO OTHER value */
  119.  
  120.             ads_mode_tile(DialogHandle, "accept", EntitiesNotSelected);
  121.  
  122.             /* Give the "Select Entities" button the focus unless entieis
  123.                have been selected (in which case give the OK button the
  124.                focus */
  125.  
  126.             if (EntitiesNotSelected == 0) {
  127.                ads_mode_tile(DialogHandle, "accept", 2);
  128.             }
  129.             else {
  130.                ads_mode_tile(DialogHandle, "SelectEnts", 2);
  131.             }
  132.  
  133.             /* Initialize the tiles */
  134.  
  135.             ads_set_tile(DialogHandle, "Tolerance", ToleranceStr);
  136.  
  137.             ads_set_tile(DialogHandle, "CheckLayer", CheckLayerStr);
  138.             ads_set_tile(DialogHandle, "CheckLType", CheckLTypeStr);
  139.             ads_set_tile(DialogHandle, "CheckColor", CheckColorStr);
  140.  
  141.  
  142.             /* Set up callbacks for the buttons */
  143.  
  144.             ads_action_tile(DialogHandle, "accept", OKCallBack);
  145.             ads_action_tile(DialogHandle, "SelectEnts", SelectCallBack);
  146.  
  147.             /* Display the dialog */
  148.  
  149.             ads_start_dialog(DialogHandle, &DialogStatus);
  150.  
  151.             /* If the "Select Entities" button was pushed, select some
  152.                entities and leave DialogStatus at 2 to re-pop the dialog
  153.                box.  If the suser really selected entities, set flag so
  154.                the OK button will be enabled */
  155.  
  156.             if (DialogStatus == 2
  157.                   && ads_ssget(NULL, NULL, NULL, NULL, SelSet) == RTNORM) {
  158.                      EntitiesNotSelected = 0;
  159.             }
  160.          }
  161.          else {
  162.             ads_printf("\nDDEEREM error: can't find EEREM dialog in EEREM.DCL\n");
  163.             stat = RSERR;
  164.          }
  165.       }
  166.  
  167.       ads_unload_dialog(DCL_ID);
  168.    }
  169.    else {
  170.       ads_printf("\nDDEEREM error: can't find EEREM.DCL\n");
  171.       stat = RSERR;
  172.    }
  173.  
  174.    /* If the user pressed OK ... */
  175.  
  176.    if (DialogStatus == 1) {
  177.  
  178.       /* Do the extra entity removal */
  179.  
  180.       DoEntityRemoval (SelSet);
  181.  
  182.    }
  183.  
  184.    /* If a selection set was created, free the memory */
  185.  
  186.    if (EntitiesNotSelected == 0) {
  187.       ads_ssfree(SelSet);
  188.    }
  189.  
  190.    ads_retvoid ();
  191.    return (stat);
  192. }
  193.  
  194. /* Callback function for the OK button */
  195.  
  196. static void CALLB OKCallBack(ads_callback_packet *CBPacket) {
  197.  
  198.    /* Get the values of the check boxes into the appropriate variables */
  199.  
  200.    ads_get_tile(CBPacket->dialog, "CheckLayer", CheckLayerStr, 2);
  201.    ads_get_tile(CBPacket->dialog, "CheckLType", CheckLTypeStr, 2);
  202.    ads_get_tile(CBPacket->dialog, "CheckColor", CheckColorStr, 2);
  203.  
  204.    CheckLayer = atoi(CheckLayerStr);
  205.    CheckLType = atoi(CheckLTypeStr);
  206.    CheckColor = atoi(CheckColorStr);
  207.  
  208.    /* Get the value of the tolerance */
  209.  
  210.    ads_get_tile(CBPacket->dialog, "Tolerance", ToleranceStr, 13);
  211.    Tolerance = atof(ToleranceStr);
  212.  
  213.    ads_done_positioned_dialog(CBPacket->dialog, 1, &DialogX, &DialogY);
  214. }
  215.  
  216. /* Callback function for the "Select Entities" button */
  217.  
  218. static void CALLB SelectCallBack(ads_callback_packet *CBPacket) {
  219.  
  220.    /* Save the current tile values */
  221.  
  222.    ads_get_tile(CBPacket->dialog, "CheckLayer", CheckLayerStr, 2);
  223.    ads_get_tile(CBPacket->dialog, "CheckLType", CheckLTypeStr, 2);
  224.    ads_get_tile(CBPacket->dialog, "CheckColor", CheckColorStr, 2);
  225.    ads_get_tile(CBPacket->dialog, "Tolerance", ToleranceStr, 13);
  226.  
  227.    /* Pop down with a status of 2 to let the user select */
  228.  
  229.    ads_done_positioned_dialog(CBPacket->dialog, 2, &DialogX, &DialogY);
  230. }
  231.